< previous page page_846 next page >

Page 846
Listing 21.45. continued
            Unload Me
        Case 1 ' refresh
            Data1.UpdateControls
        Case 2 ' update
            Data1_Validate vbDataActionUpdate, 1
            Data1.UpdateRecord
        Case 3 ' add
            Data1.Recordset.AddNew
            txtField(0).SetFocus
        Case 4 ' delete
            objLog.WriteLog "Delete", Data1.RecordSource, txtField(0).DataField,
txtField(0), ""
            objLog.WriteLog "Delete", Data1.RecordSource, txtField(1).DataField,
txtField(1), ""
            objLog.WriteLog "Delete", Data1.RecordSource, txtField(2).DataField,
txtField(2), ""
            Data1.Recordset.Delete
            Data1.Recordset.MovePrevious
    End Select
    '
    Exit Sub
    '
LocalErr:
    MsgBox Err.Description, vbExclamation, Err.Number
    '
End Sub
Note that there are steps to write deleted records to the audit file, but not to log edits or adds. These transactions are handled in the Validate event of the data control.
There is one support routine you need to add to the form. This routine is used to generate a "friendly name" for each of the action codes that occur in the Validate parameter list. Add the code in Listing 21.46 to your form.
Type.gifListing 21.46. Coding the GetAction method.
Public Function GetAction(intAction As Integer) As String
    '
    ' convert action constant into friendly name
    '
    Select Case intAction
        Case vbDataActionMoveFirst '1
            GetAction = "MoveFirst"
        Case vbDataActionMovePrevious '2
            GetAction = "MovePrevious"
        Case vbDataActionMoveNext '3
            GetAction = "MoveNext"
        Case vbDataActionMoveLast '4
            GetAction = "MoveLast"

 
< previous page page_846 next page >

If you like this book, buy it!